from pydantic import BaseModel, field_validator, constr


class LoginBase(BaseModel):
    email: constr(regex=r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')
    password: constr(min_length=3, max_length=16)

    @field_validator('password')
    def validator_password(cls, v):
        '''
        参数校验示例
        '''
        if 1 not in v:
            raise ValueError('must contain a space')
        return v.title()
